using IFramework;
using System;
using UnityEngine;
namespace IFramework
{

    public class UIItem : MonoBehaviour, IPoolObj,IObserver
    {
        public Type ObjType
        {
            get
            {
                return GetType();
            }
        }

        public UIData Data { get { return data; }set { data = value; } }
        protected UIData data;
        public UIBase UIParent { get { return uiParent; } set { uiParent = value; } }

        public object Content
        {
            get
            {
                return this;
            }
        }

        protected UIBase uiParent;
        public virtual void SetViewData()
        {
            data.ReFresh();
        }

        public virtual void OnExit(params object[] paras)
        {
            ObserveManager.Instance.RemoveObserver(UIParent, this);
        }
        public virtual void OnEnter(params object[] paras)
        {
            ObserveManager.Instance.AddObserver(UIParent, this);
            SetViewData();
        }

        public void OnCreate(params object[] paras)
        {
            OnEnter(paras);
        }

        public void OnReuse(params object[] paras)
        {
            OnEnter(paras);
        }

        public void OnRestore(params object[] paras)
        {
            OnExit(paras);
        }

        public virtual void OnClean(params object[] paras)
        {

        }

        public virtual void Listen(EventArgs args, Type eventType, int code, params object[] message)
        {
        }
    }
}